<template>
  <div>
    <!-- 处置信息 -->
    <div class="info">
      <!-- 状态 -->
      <div class="item title">
        <div class="item-line">
          <div class="label">信息标题：</div>
          <div class="value">{{ detail.title }}</div>
        </div>
        <el-tag size="small" class="tag">{{ stsList.find((item) => item.id === detail.sts) && stsList.find((item) => item.id === detail.sts).text }}</el-tag>
      </div>
      <div class="item">
        <div class="label">所属分类：</div>
        <div class="value">{{ detail.cate_name }}</div>
      </div>
      <div class="item">
        <div class="label">所属地区：</div>
        <div class="value">{{ detail.address }}</div>
      </div>
      <div class="item">
        <div class="label">估值：</div>
        <div class="value">{{ detail.guzhi }}</div>
      </div>
      <div class="item">
        <div class="label">数量：</div>
        <div class="value">{{ detail.num }}</div>
      </div>
      <div class="item">
        <div class="label">联系人：</div>
        <div class="value">{{ detail.user_name }}</div>
      </div>
      <div class="item">
        <div class="label">联系电话：</div>
        <div class="value">{{ detail.user_phone }}</div>
      </div>
    </div>
    <!-- 回访记录 -->
    <div class="contact-list" v-if="showModule === 'all'">
      <el-empty class="empty" :image-size="100" v-if="contactRecord.length === 0" description="暂无回访记录"></el-empty>
      <el-timeline v-else class="list">
        <el-timeline-item v-for="item in contactRecord" :key="item.id">
          <div class="item">
            <div class="line">
              <p class="text">人工联系</p>
              <p class="text">联系时间: {{ item.created_time }}</p>
            </div>
            <p class="line">是否成交：{{ item.is_success === 1 ? '是' : '否' }}</p>
            <p class="line">备注：{{ item.message }}</p>
          </div>
        </el-timeline-item>
      </el-timeline>
      <el-button size="mini" type="primary" @click="handleAddContact">添加回访记录</el-button>
    </div>

    <!-- 添加回访记录 -->
    <el-dialog title="添加回访记录" :visible.sync="showContactRecord" :modal="false">
      <ContactRecord :has-deal="hasDeal" :customerList="customerList" v-if="showContactRecord" :id="id" @confirm="handleContactConfirm" @close="showContactRecord = false" />
    </el-dialog>
  </div>
</template>
<script>
import { apiPushDetail, apiPushLeftContact } from '@/api/assetsDisposal'
import ContactRecord from './ContactRecord'

export default {
  props: {
    showModule: {
      type: String,
      default: 'all',
    },
    id: String,
    stsList: Array,
    hasDeal: Boolean,
    customerList: {
      type: Array,
      default: () => {
        return []
      },
    },
  },
  components: { ContactRecord },
  data() {
    return {
      loading: false,
      detail: {},
      contactRecord: [],
      showContactRecord: false,
    }
  },
  mounted() {
    this.getDetail()
  },
  methods: {
    // 获取详情
    getDetail() {
      const info = {
        id: this.id,
      }
      const formData = new FormData()
      for (let key in info) {
        formData.set(key, info[key])
      }
      apiPushDetail(formData).then((res) => {
        if (res.code !== 200) {
          return
        }
        this.detail = res.data
        this.$emit('getdetail', this.detail)
      })
      if (this.showModule === 'all') {
        apiPushLeftContact(formData).then((res) => {
          if (res.code !== 200) {
            return
          }
          this.contactRecord = res.data
        })
      }
    },
    // 添加回访记录
    handleAddContact() {
      this.showContactRecord = true
    },
    // 添加回访记录
    handleContactConfirm() {
      this.showContactRecord = false
      const info = {
        id: this.id,
      }
      const formData = new FormData()
      for (let key in info) {
        formData.set(key, info[key])
      }
      apiPushLeftContact(formData).then((res) => {
        if (res.code !== 200) {
          return
        }
        this.$message.success('操作成功')
        this.contactRecord = res.data
      })
    },
  },
}
</script>
<style scoped lang="scss">
.info {
  margin: 0 24px;
  background: #efefef;
  padding: 10px 20px;
  font-size: 14px;
  color: #333333;
  margin-bottom: 30px;
  position: relative;
  .item,
  .item-line {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    line-height: 2;

    .label {
      width: 100px;
      flex-shrink: 0;
    }
    &.title {
      display: flex;
      justify-content: space-between;
    }
    .tag {
      margin-left: 2px;
    }
  }
}

.contact-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  .list {
    padding: 0 24px;
    margin-bottom: 16px;
    max-height: calc(100vh - 430px);
    overflow: hidden;
    overflow-y: auto;
    font-size: 12px;
    width: 100%;
    .item {
      width: 100%;
      background: #efefef;
      padding: 10px 20px;
      .line {
        width: 100%;
        display: flex;
        justify-content: space-between;
        p {
          margin-top: 0;
        }
      }
    }
  }
}
</style>
